package gold.digger;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

/**
 * Created by fanzhenyu02 on 2020/6/27.
 * common problem solver template.
 */
public class LC119 {
    public long startExecuteTime = System.currentTimeMillis();


    class Solution {
        public List<Integer> getRow(int rowIndex) {
            if (rowIndex <= 0) return new ArrayList<>(Arrays.asList(1));

            List<Integer> curRow = new ArrayList<>();
            List<Integer> preRow = new ArrayList<>();
            preRow.add(1);

            for (int i = 1; i <= rowIndex; i++) {
                curRow = new ArrayList<>();
                curRow.add(1);
                for (int j = 0; j < preRow.size() - 1; j++) {
                    curRow.add(preRow.get(j) + preRow.get(j + 1));
                }
                curRow.add(1);
                preRow = curRow;
            }

            return curRow;
        }
    }

    public void run() {
        Solution solution = new Solution();
        System.out.println(solution.getRow(3));
    }

    public static void main(String[] args) throws Exception {
        LC119 an = new LC119();
        an.run();

        System.out.println("\ncurrent solution total execute time: " + (System.currentTimeMillis() - an.startExecuteTime) + " ms.");
    }
}
